#include "stdafx.h"
#include "ZStreamable.h"
#include "ZStreamBuf.h"

namespace	Z	{

//------------------------------------------------------------------------------------------------------------------------
_ZMainApi	void	writeString(Streamable& streamable, const char* str)
{
	const size_t len	= strlen(str);
	streamable << len;
	streamable.write(str, len);
}

_ZMainApi	void	readString(Streamable& streamable, char* str, size_t kSize)
{
	size_t len;
	streamable >> len;
	const size_t readSize	= std::min<size_t>(len, kSize - 1);
	streamable.read(str, readSize);
	str[readSize]	= '\0';
}

_ZMainApi	void	writeString(Streamable& streamable, const std::string& str)
{
	writeString(streamable, str.c_str());
}

_ZMainApi	void	readString(Streamable& streamable, std::string& str, size_t kSize)	{
	StreamBuf buf(kSize);
	readString(streamable, buf, kSize);
	str	= buf;
}

}